const express=require('express');
const cookieParser=require('cookie-parser');

var server=express();

//cookie
server.use('/aaa/a.html',function(req,res){   
    res.cookie('user','yexuan',{ path:'/aaa',maxAge:30*24*3600*1000 }); 
    //30*24*3600*1000为一个月---->1969-12-31T23:59:59.000Z
    res.send('ok');
});

server.use(cookieParser());
server.use('/',function(req,res){
    req.secret='--yx--';
    res.cookie('user','yexuan',{signed:true});  
    //cookie签名过后，以字母s开头；
    //签名过后cookie：s%3Ayexuan.Qq8N%2B%2BLWDqbfBcdkb3%2B%2Bi%2Bch6pTDBWap%2FCYUjJosVCo；
    console.log(req.cookies);
    res.send('ok');
});

server.use(cookieParser('--yx--'));
//将secret字符添加到cookieParser()里边，就能进行解密
server.use('/',function(req,res){
    req.secret='--yx--';
    res.cookie('user','yexuan',{signed:true});  
    console.log(req.cookies);           //未签名cookie
    console.log(req.signedCookies);     //已签名cookie
    res.send('ok');
});


server.listen(11111);